{% extends 'index.html' %}
{% block ace-content %}
<!-- Search -->   
<link rel="stylesheet" href="/static/dist/css/jquery-ui.min.css">
<script src="/static/dist/js/jquery-ui.min.js"></script>  
<style type="text/css"> 	
	td.details-control {
	    background: url('/static/img/details_open.png') no-repeat center center; */
	    cursor: pointer;
	}
	tr.shown td.details-control {
	    background: url('/static/img/details_close.png') no-repeat center center;
	} 
</style>   
{% endblock %}
{% block page-content %}

<div id="page-wrapper">
    <div class="row">
         <div class="col-lg-12">
              <h1 class="page-header"><i class="fa  fa-search"></i> 设备资产查询</h1>
         </div>
                <!-- /.col-lg-12 -->
    </div>
	<div class="row">
		<div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                            	<i class="fa fa-search-plus"></i> 查询类型 
                </div>
                        
                <div class="panel-body">

				   <div class="row" >
				      <div class="col-xs-6 col-sm-3">
							<div class="form-group">
								<label class="col-sm-3 control-label">设备类型:</label>
								<div class="col-sm-8">
									 <select class="form-control" id="selAssetsType" >
									 		<option selected="selected" value="">请选择一个类型</option>
											<option value="server" name="assets_type">服务器</option>
											<option value="vmser" name="assets_type">虚拟机</option>	
											<option value="switch" name="assets_type">交换机</option>	
											<option value="route" name="assets_type">路由器</option>	
											<option value="printer" name="assets_type">打印机</option>	
											<option value="scanner" name="assets_type">扫描仪</option>		
											<option value="firewall" name="assets_type">防火墙</option>	
											<option value="storage" name="assets_type">存储设备</option>	
											<option value="wifi" name="assets_type">无线设备</option>				
									</select>
								</div>
							</div>
				      </div>
				      <div class="col-xs-6 col-sm-3">
							<div class="form-group">
								<label class="col-sm-3 control-label">制造商:</label>
								<div class="col-sm-8">
									 <select class="form-control" id="selManufacturer" >
									 	<option selected="selected" value="">请选择一个类型</option>
									 	{% for m in manufacturerList %}
									 		<option value="{{m}}" name="manufacturer">{{m}}</option>
									 	{% endfor %}
									</select>
								</div>
							</div>
				      </div>
				
				      <div class="col-xs-6 col-sm-3">
							<div class="form-group">
								<label class="col-sm-3 control-label">供货商:</label>
								<div class="col-sm-8">
									 <select class="form-control" id="selProvider" >
									 	<option selected="selected" value="">请选择一个类型</option>
									 	{% for m in providerList %}
									 		<option value="{{m}}" name="provider">{{m}}</option>
									 	{% endfor %}														
									</select>
								</div>
							</div>
				      </div>
				
				      <div class="col-xs-6 col-sm-3">
							<div class="form-group">
								<label class="col-sm-3 control-label">设备型号:</label>
								<div class="col-sm-8">
									 <select class="form-control" id="selModel" >
									 	<option selected="selected" value="">请选择一个类型</option>
									 	{% for m in modelList %}
									 		<option value="{{m}}" name="model">{{m}}</option>
									 	{% endfor %}				
									</select>
								</div>
							</div>
				      </div>	   
				   </div>
                	<hr>
				   <div class="row" >
				      <div class="col-xs-6 col-sm-3">
							<div class="form-group">
								<label class="col-sm-3 control-label">Raid类型:</label>
								<div class="col-sm-8">
									<select class="form-control"  id="selRaid"  >
										<option selected="selected" value="">请选择一个类型</option>
									 	{% for r in baseAssets.raid %}
									 		<option value="{{r.id}}" name="raid">{{r.raid_name}}</option>
									 	{% endfor %}												   		
									</select>
								</div>
							</div>
				      </div>
				      <div class="col-xs-6 col-sm-3">
							<div class="form-group">
								<label class="col-sm-3 control-label">CPU类型:</label>
								<div class="col-sm-8">
									 <select class="form-control" id="selCpu" >
									 	<option selected="selected" value="">请选择一个类型</option>
									 	{% for c in cpuList %}
									 		<option value="{{c}}" name="cpu">{{c}}</option>
									 	{% endfor %}				
									</select> 
								</div>
							</div>
				      </div>
				
				      <div class="col-xs-6 col-sm-3">
							<div class="form-group">
								<label class="col-sm-3 control-label">购买人:</label>
								<div class="col-sm-8">
									 <select class="form-control" id="selBuyUser" >
									 	<option selected="selected" value="">请选择一个类型</option>
									 	{% for b in buyUserList %}
									 		<option value="{{b.id}}" name="buy_user">{{b.username}}</option>
									 	{% endfor %}										 				
									</select>
								</div>
							</div>
				      </div>
				
				      <div class="col-xs-6 col-sm-3">
							<div class="form-group">
								<label class="col-sm-3 control-label">认证方式:</label>
								<div class="col-sm-8">
									 <select class="form-control" id="selKeyfile" >
									 	<option selected="selected" value="">请选择一个类型</option>
										<option value="1" name="keyfile">密钥认证</option>
										<option value="0" name="keyfile">密码认证</option>					
									</select>
								</div>
							</div>
				      </div>	   
				   </div>                
                
                <hr>
				   <div class="row" >
				      <div class="col-xs-6 col-sm-3">
							<div class="form-group">
								<label class="col-sm-3 control-label">线路类型:</label>
								<div class="col-sm-8">
									 <select class="form-control" id="selLine" >
									 	<option selected="selected" value="">请选择一个类型</option>
									 	{% for l in baseAssets.line %}
									 		<option value="{{l.id}}" name="line">{{l.line_name}}</option>
									 	{% endfor %}									 			
									</select>
								</div>
							</div>
				      </div>
				      <div class="col-xs-6 col-sm-3">
							<div class="form-group">
								<label class="col-sm-3 control-label">设备状态:</label>
								<div class="col-sm-8">
									<select class="form-control"  id="selStatus"  >
										<option selected="selected" value="">请选择一个类型</option>
										<option value="0" name="status">已上线</option>	
										<option value="1" name="status">已下线</option>	
										<option value="2" name="status">维修中</option>	
										<option value="3" name="status">已入库</option>	
										<option value="4" name="status">未使用</option>				   		
									</select>
								</div>
							</div>
				      </div>
				
				      <div class="col-xs-6 col-sm-3">
							<div class="form-group">
								<label class="col-sm-3 control-label">使用部门:</label>
								<div class="col-sm-8">
								 	<select class="form-control" id="selGroup" >
									 	<option selected="selected" value="">请选择一个类型</option>
									 	{% for g in baseAssets.group %}
									 		<option value="{{g.id}}" name="group">{{g.name}}</option>
									 	{% endfor %}									 				
									</select> 
								</div>
							</div>
				      </div>
				
				      <div class="col-xs-6 col-sm-3">
							<div class="form-group">
								<label class="col-sm-3 control-label">所属业务:</label>
								<div class="col-sm-8">
									 <select class="form-control" id="selBusiness" >
									 	<option selected="selected" value="">请选择一个类型</option>
									 	{% for s in baseAssets.service %}
									 		<option value="{{s.id}}" name="business">{{s.service_name}}</option>
									 	{% endfor %}										 					
									</select> 
								</div>
							</div>
				      </div>	   
				   </div>                
                
                   <hr>
				   <div class="row" >
				      <div class="col-xs-6 col-sm-3">
							<div class="form-group">
								<label class="col-sm-3 control-label">所在机房:</label>
								<div class="col-sm-8">
									 <select class="form-control" id="selZone" >
									 	<option selected="selected" value="">请选择一个类型</option>
									 	{% for z in baseAssets.zone %}
									 		<option value="{{z.id}}" name="put_zone">{{z.zone_name}}</option>
									 	{% endfor %}			
									</select>
								</div>
							</div>
				      </div>
				      <div class="col-xs-6 col-sm-3">
							<div class="form-group">
								<label class="col-sm-3 control-label">所属产品线:</label>
								<div class="col-sm-8">
									 <select class="form-control" id="selProject" >
									 	<option selected="selected" value="">请选择一个类型</option>
									 	{% for b in baseAssets.project %}
									 		<option value="{{b.id}}" name="project">{{b.project_name}}</option>
									 	{% endfor %}				
									</select>
								</div>
							</div>
				      </div>
				
				      <div class="col-xs-6 col-sm-3">
							<div class="form-group">
								<label class="col-sm-3 control-label">系统版本:</label>
								<div class="col-sm-8">
									 <select class="form-control" id="selSystem" >
									 	<option selected="selected" value="">请选择一个类型</option>
									 	{% for b in systemList %}
									 		<option value="{{b}}" name="system">{{b}}</option>
									 	{% endfor %}																
									</select>
								</div>
							</div>
				      </div>
				
				      <div class="col-xs-6 col-sm-3">
							<div class="form-group">
								<label class="col-sm-3 control-label">内核版本:</label>
								<div class="col-sm-8">
									 <select class="form-control" id="selKernel" >
									 	<option selected="selected" value="">请选择一个类型</option>
									 	{% for k in kernelList %}
									 		<option value="{{k}}" name="kernel">{{k}}</option>
									 	{% endfor %}										 					
									</select> 
								</div>
							</div>
				      </div>	   
				   </div>   
                   <hr>
				   <div class="row" >
				      <div class="col-xs-6 col-sm-3">
							<div class="form-group">
								<label class="col-sm-3 control-label">逻辑CPU:</label>
								<div class="col-sm-8">
									<input type="text" id="vcpu_number" style="border:0; color:#f6931f; font-weight:bold;">
									<div id="vcpu_number-range"></div>
								</div>
							</div>
				      </div>
				      <div class="col-xs-6 col-sm-3">
							<div class="form-group">
								<label class="col-sm-3 control-label">物理CPU:</label>
								<div class="col-sm-8">
									<input type="text" id="cpu_number" style="border:0; color:#f6931f; font-weight:bold;">								 
									<div id="cpu_number-range"></div>
								</div>
							</div>
				      </div>
				
				      <div class="col-xs-6 col-sm-3">
							<div class="form-group">
								<label class="col-sm-3 control-label">CPU核心数:</label>
								<div class="col-sm-8">
									<input type="text" id="cpu_core" style="border:0; color:#f6931f; font-weight:bold;">
									<div id="cpu_core-range"></div>
								</div>
							</div>
				      </div>
				
				      <div class="col-xs-6 col-sm-3">
							<div class="form-group">
								<label class="col-sm-3 control-label">Swap区间:</label>
								<div class="col-sm-8">
									<input type="text" id="swap" style="border:0; color:#f6931f; font-weight:bold;">
									<div id="swap-range"></div>
								</div>
							</div>
				      </div>	   
				   </div> 				                                                                
 				   <hr>
				   <div class="row" >
				      <div class="col-xs-6 col-sm-3">
							<div class="form-group">
								<label class="col-sm-3 control-label">内存区间:</label>
								<div class="col-sm-8">
									<input type="text" id="ram_total" style="border:0; color:#f6931f; font-weight:bold;">
									<div id="ram_total-range"></div>
								</div>
							</div>
				      </div>
				      <div class="col-xs-6 col-sm-3">
							<div class="form-group">
								<label class="col-sm-3 control-label">硬盘容量:</label>
								<div class="col-sm-8">
									<input type="text" id="disk_total" style="border:0; color:#f6931f; font-weight:bold;">
									<div id="disk_total-range"></div>
								</div>
							</div>
				      </div>
				
				      <div class="col-xs-6 col-sm-3">
							<div class="form-group">
								<label class="col-sm-3 control-label">购买年份:</label>
								<div class="col-sm-8">
									<input type="text" id="buy_time" style="border:0; color:#f6931f; font-weight:bold;">
									<div id="buy_time-range"></div>
								</div>
							</div>
				      </div>
				
				      <div class="col-xs-6 col-sm-3">
							<div class="form-group">
								<label class="col-sm-3 control-label">过保年份:</label>
								<div class="col-sm-8">
									<input type="text" id="expire_date" style="border:0; color:#f6931f; font-weight:bold;">
									<div id="expire_date-range"></div>
								</div>
							</div>
				      </div>	   
				   </div> 				                                                                      
                        
                    </div>
                </div>        
            </div>

            
		<div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                            <i class="fa fa-check "></i> 已选条件
                </div>
                        
                <div class="panel-body">
                        <div id="divSelectedType">
                        </div>
                </div>
            </div>
         </div>   
 
		<div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                           <i class="fa fa-tasks "></i> 结果列表
                </div>
                        
                <div class="panel-body">
                	<div id="div-search-result" style="display:none;">
                		<div class="col-lg-10">
                		</div>                       
                        <div>
							<table   width="100%" class="table table-striped table-bordered table-hover dataTable no-footer" id="dataTables-Search">						
	                                <thead>
								            <tr>
								               <th class="text-center">详情</th>
								               <th class="text-center">资产ID</th>
										       <th class="text-center">资产类型</th>
										       <th class="text-center">管理IP</th>
										       <th class="text-center">资产编号</th>
										       <th class="text-center">设备型号</th>
										       <th class="text-center">放置区域</th>
										       <th class="text-center">产品线</th>
										       <th class="text-center">业务类型</th>
										       <th class="text-center">使用组</th>
										       <th class="text-center">设备状态</th>
										       <th class="text-center">操作</th>
								            </tr>
									        <tfoot>
								            <tr>
								               <th class="text-center">详情</th>
								               <th class="text-center">资产ID</th>
										       <th class="text-center">资产类型</th>
										       <th class="text-center">管理IP</th>
										       <th class="text-center">资产编号</th>
										       <th class="text-center">设备型号</th>
										       <th class="text-center">放置区域</th>
										       <th class="text-center">产品线</th>
										       <th class="text-center">业务类型</th>
										       <th class="text-center">使用组</th>
										       <th class="text-center">设备状态</th>
										       <th class="text-center">操作</th>
								            </tr>
									        </tfoot>										    
	                                </thead>                                
	                       	</table>
                       	</div>
                   </div>                   
                </div>
            </div>
         </div>                   
            	
    </div>    
    
</div>


    <script type="text/javascript">
        
	    


        var curpage = 1;
        $(document).ready(function () {
/*             $('.assets_add').leanModal({ top: 100, overlay: 0.45, closeButton: ".pb-x" }); */
            //物理CPU个数区间
            $("#cpu_number-range").slider({
			    range: "min",
			    value: 0,
			    min: 1,
			    max: 10,
                values: [1, 10],
                slide: function (event, ui) {
                    if (ui.values[0] != ui.values[1]) {
                        $("#cpu_number").val(ui.values[0] + " - " + ui.values[1] + "颗");
                    }
                    else {
                        $("#cpu_number").val(ui.values[0] + "颗");
                    }
                },
                change: function (event, ui) {
                    var span = "<span class='label label-success' id='spanCpuNmuber'>物理CPU个数：" + ui.values[0] + "-" + ui.values[1] +
                     "颗  <img alt='' src='/static/img/close.png' onclick='removeself(this)' /><input name='cpu_number' type='hidden' value='"
                     + ui.values[0] + "-" + ui.values[1] + "' /></span> &nbsp;";
                    if ($("#spanCpuNmuber").length == 0) {
                        $('#divSelectedType').append(span);
                    }
                    else {
                        $("#spanCpuNmuber").html("物理CPU个数" + ui.values[0] + "-" + ui.values[1] +
                         "颗  <img alt='' src='/static/img/close.png' onclick='removeself(this)' /><input name='cpu_number' type='hidden' value='"
                     + ui.values[0] + "-" + ui.values[1] + "' /></span> &nbsp;");
                    }
                    changepage(1);
                }
            });
            $("#cpu_number").val($("#cpu_number-range").slider("values", 0) +
			" - " + $("#cpu_number-range").slider("values", 1) + "颗");


            //逻辑CPU个数区间
            $("#vcpu_number-range").slider({
			    range: "min",
			    value: 0,
			    min: 1,
			    max: 10,
                values: [1, 10],
                slide: function (event, ui) {
                    if (ui.values[0] != ui.values[1]) {
                        $("#vcpu_number").val(ui.values[0] + " - " + ui.values[1] + "颗");
                    }
                    else {
                        $("#vcpu_number").val(ui.values[0] + "颗");
                    }
                },
                change: function (event, ui) {
                    var span = "<span class='label label-success' id='spanVcpuNmuber'>逻辑CPU个数：" + ui.values[0] + "-" + ui.values[1] +
                     "颗  <img alt='' src='/static/img/close.png' onclick='removeself(this)' /><input name='vcpu_number' type='hidden' value='"
                     + ui.values[0] + "-" + ui.values[1] + "' /></span> &nbsp;";
                    if ($("#spanVcpuNmuber").length == 0) {
                        $('#divSelectedType').append(span);
                    }
                    else {
                        $("#spanVcpuNmuber").html("逻辑CPU个数：" + ui.values[0] + "-" + ui.values[1] +
                         "颗  <img alt='' src='/static/img/close.png' onclick='removeself(this)' /><input name='vcpu_number' type='hidden' value='"
                     + ui.values[0] + "-" + ui.values[1] + "' /></span> &nbsp;");
                    }
                    changepage(1);
                }
            });
            $("#vcpu_number").val($("#vcpu_number-range").slider("values", 0) +
			" - " + $("#vcpu_number-range").slider("values", 1) + "颗");

            //CPU核心个数区间
            $("#cpu_core-range").slider({
			    range: "min",
			    value: 0,
			    min: 1,
			    max: 10,
                values: [1, 10],
                slide: function (event, ui) {
                    if (ui.values[0] != ui.values[1]) {
                        $("#cpu_core").val(ui.values[0] + " - " + ui.values[1] + "颗");
                    }
                    else {
                        $("#cpu_core").val(ui.values[0] + "颗");
                    }
                },
                change: function (event, ui) {
                    var span = "<span class='label label-success' id='spanCpuCore'>逻辑CPU个数：" + ui.values[0] + "-" + ui.values[1] +
                     "颗  <img alt='' src='/static/img/close.png' onclick='removeself(this)' /><input name='cpu_core' type='hidden' value='"
                     + ui.values[0] + "-" + ui.values[1] + "' /></span> &nbsp;";
                    if ($("#spanCpuCore").length == 0) {
                        $('#divSelectedType').append(span);
                    }
                    else {
                        $("#spanCpuCore").html("逻辑CPU个数：" + ui.values[0] + "-" + ui.values[1] +
                         "颗  <img alt='' src='/static/img/close.png' onclick='removeself(this)' /><input name='cpu_core' type='hidden' value='"
                     + ui.values[0] + "-" + ui.values[1] + "' /></span> &nbsp;");
                    }
                    changepage(1);
                }
            });
            $("#cpu_core").val($("#cpu_core-range").slider("values", 0) +
			" - " + $("#cpu_core-range").slider("values", 1) + "颗");            
            
			//CPU类型
            $('#selCpu').change(function () {
                if ($('#selCpu').val() != "") {
                    $("#hdnCpu").val($('#selCpu').val());
                    var span = "<span class='label label-success' id='spanCpu'>" + $("#selCpu").find("option:selected").text()
                    + " <img alt='' src='/static/img/close.png' onclick='removeself(this)' /><input name='cpu' type='hidden' value='"
                    + $('#selCpu').val() + "' /></span> &nbsp;";
                    if ($("#spanCpu").length == 0) {
                        $('#divSelectedType').append(span);
                    }
                    else {
                        $("#spanCpu").html($("#selCpu").find("option:selected").text()
                         + " <img alt='' src='/static/img/close.png' onclick='removeself(this)' /><input name='cpu' type='hidden' value='"
                         + $('#selCpu').val() + "' /></span> &nbsp;");
                    }
                    changepage(1);
                }
            })
			//认证类型
            $('#selKeyfile').change(function () {
                if ($('#selKeyfile').val() != "") {
                    $("#hdnKeyfile").val($('#selKeyfile').val());
                    var span = "<span class='label label-success' id='spanKeyfile'>" + $("#selKeyfile").find("option:selected").text()
                    + " <img alt='' src='/static/img/close.png' onclick='removeself(this)' /><input name='keyfile' type='hidden' value='"
                    + $('#selKeyfile').val() + "' /></span> &nbsp;";
                    if ($("#spanKeyfile").length == 0) {
                        $('#divSelectedType').append(span);
                    }
                    else {
                        $("#spanKeyfile").html($("#selKeyfile").find("option:selected").text()
                         + " <img alt='' src='/static/img/close.png' onclick='removeself(this)' /><input name='keyfile' type='hidden' value='"
                         + $('#selKeyfile').val() + "' /></span> &nbsp;");
                    }
                    changepage(1);
                }
            })
			//设备类型
            $('#selAssetsType').change(function () {
                if ($('#selAssetsType').val() != "") {
                    $("#hdnAssetsType").val($('#selAssetsType').val());
                    var span = "<span class='label label-success' id='spanAssetsType'>" + $("#selAssetsType").find("option:selected").text()
                    + " <img alt='' src='/static/img/close.png' onclick='removeself(this)' /><input name='assets_type' type='hidden' value='"
                    + $('#selAssetsType').val() + "' /></span> &nbsp;";
                    if ($("#spanAssetsType").length == 0) {
                        $('#divSelectedType').append(span);
                    }
                    else {
                        $("#spanAssetsType").html($("#selAssetsType").find("option:selected").text()
                         + " <img alt='' src='/static/img/close.png' onclick='removeself(this)' /><input name='assets_type' type='hidden' value='"
                         + $('#selAssetsType').val() + "' /></span> &nbsp;");
                    }
                    changepage(1);
                }
            })
			//生产制造商
            $('#selManufacturer').change(function () {
                if ($('#selManufacturer').val() != "") {
                    $("#hdnManufacturer").val($('#selManufacturer').val());
                    var span = "<span class='label label-success' id='spanManufacturer'>" + $("#selManufacturer").find("option:selected").text()
                    + " <img alt='' src='/static/img/close.png' onclick='removeself(this)' /><input name='manufacturer' type='hidden' value='"
                    + $('#selManufacturer').val() + "' /></span> &nbsp;";
                    if ($("#spanManufacturer").length == 0) {
                        $('#divSelectedType').append(span);
                    }
                    else {
                        $("#spanManufacturer").html($("#selManufacturer").find("option:selected").text()
                         + " <img alt='' src='/static/img/close.png' onclick='removeself(this)' /><input name='manufacturer' type='hidden' value='"
                         + $('#selManufacturer').val() + "' /></span> &nbsp;");
                    }
                    changepage(1);
                }
            })        
            //设备型号
            $('#selModel').change(function () {
                if ($('#selModel').val() != "") {
                    $("#hdnModel").val($('#selModel').val());
                    var span = "<span class='label label-success' id='spanModel'>" + $("#selModel").find("option:selected").text()
                    + " <img alt='' src='/static/img/close.png' onclick='removeself(this)' /><input name='model' type='hidden' value='"
                    + $('#selModel').val() + "' /></span> &nbsp;";
                    if ($("#spanModel").length == 0) {
                        $('#divSelectedType').append(span);
                    }
                    else {
                        $("#spanModel").html($("#selModel").find("option:selected").text()
                         + " <img alt='' src='/static/img/close.png' onclick='removeself(this)' /><input name='model' type='hidden' value='"
                         + $('#selModel').val() + "' /></span> &nbsp;");
                    }
                    changepage(1);
                }
            }) 
            //供货商
            $('#selProvider').change(function () {
                if ($('#selProvider').val() != "") {
                    $("#hdnProvider").val($('#selProvider').val());
                    var span = "<span class='label label-success' id='spanProvider'>" + $("#selProvider").find("option:selected").text()
                    + " <img alt='' src='/static/img/close.png' onclick='removeself(this)' /><input name='provider' type='hidden' value='"
                    + $('#selProvider').val() + "' /></span> &nbsp;";
                    if ($("#spanProvider").length == 0) {
                        $('#divSelectedType').append(span);
                    }
                    else {
                        $("#spanProvider").html($("#selProvider").find("option:selected").text()
                         + " <img alt='' src='/static/img/close.png' onclick='removeself(this)' /><input name='provider' type='hidden' value='"
                         + $('#selProvider').val() + "' /></span> &nbsp;");
                    }
                    changepage(1);
                }
            })  
            //Raid类型
            $('#selRaid').change(function () {
                if ($('#selRaid').val() != "") {
                    $("#hdnRaid").val($('#selRaid').val());
                    var span = "<span class='label label-success' id='spanRaid'>" + $("#selRaid").find("option:selected").text()
                    + " <img alt='' src='/static/img/close.png' onclick='removeself(this)' /><input name='raid' type='hidden' value='"
                    + $('#selRaid').val() + "' /></span> &nbsp;";
                    if ($("#spanRaid").length == 0) {
                        $('#divSelectedType').append(span);
                    }
                    else {
                        $("#spanRaid").html($("#selRaid").find("option:selected").text()
                         + " <img alt='' src='/static/img/close.png' onclick='removeself(this)' /><input name='raid' type='hidden' value='"
                         + $('#selRaid').val() + "' /></span> &nbsp;");
                    }
                    changepage(1);
                }
            })   
            //内存区间
            $("#ram_total-range").slider({
			    range: "min",
			    value: 0,
			    min: 512,
			    max: 1048576,
                values: [1024, 4096],
                slide: function (event, ui) {
                    if (ui.values[0] != ui.values[1]) {
                        $("#ram_total").val(ui.values[0] + " - " + ui.values[1] + "MB");
                    }
                    else {
                        $("#ram_total").val(ui.values[0] + "MB");
                    }
                },
                change: function (event, ui) {
                    var span = "<span class='label label-success' id='spanRamTotal'>内存区间：" + ui.values[0] + "-" + ui.values[1] +
                     "MB <img alt='' src='/static/img/close.png' onclick='removeself(this)' /><input name='ram_total' type='hidden' value='"
                     + ui.values[0] + "-" + ui.values[1] + "' /></span> &nbsp;";
                    if ($("#spanRamTotal").length == 0) {
                        $('#divSelectedType').append(span);
                    }
                    else {
                        $("#spanRamTotal").html("内存区间：" + ui.values[0] + "-" + ui.values[1] +
                         "MB  <img alt='' src='/static/img/close.png' onclick='removeself(this)' /><input name='ram_total' type='hidden' value='"
                     + ui.values[0] + "-" + ui.values[1] + "' /></span> &nbsp;");
                    }
                    changepage(1);
                }
            });
            $("#ram_total").val($("#ram_total-range").slider("values", 0) +
			" - " + $("#ram_total-range").slider("values", 1) + "MB"); 
            
            //Swap区间
            $("#swap-range").slider({
			    range: "min",
			    value: 0,
			    min: 512,
			    max: 16384,
                values: [1024, 4096],
                slide: function (event, ui) {
                    if (ui.values[0] != ui.values[1]) {
                        $("#swap").val(ui.values[0] + " - " + ui.values[1] + "MB");
                    }
                    else {
                        $("#swap").val(ui.values[0] + "MB");
                    }
                },
                change: function (event, ui) {
                    var span = "<span class='label label-success' id='spanSwap'>Swap区间：" + ui.values[0] + "-" + ui.values[1] +
                     "MB <img alt='' src='/static/img/close.png' onclick='removeself(this)' /><input name='swap' type='hidden' value='"
                     + ui.values[0] + "-" + ui.values[1] + "' /></span> &nbsp;";
                    if ($("#spanSwap").length == 0) {
                        $('#divSelectedType').append(span);
                    }
                    else {
                        $("#spanSwap").html("Swap区间：" + ui.values[0] + "-" + ui.values[1] +
                         "MB  <img alt='' src='/static/img/close.png' onclick='removeself(this)' /><input name='swap' type='hidden' value='"
                     + ui.values[0] + "-" + ui.values[1] + "' /></span> &nbsp;");
                    }
                    changepage(1);
                }
            });
            $("#swap").val($("#swap-range").slider("values", 0) +
			" - " + $("#swap-range").slider("values", 1) + "MB");  
            
            //disk_total区间
            $("#disk_total-range").slider({
			    range: "min",
			    value: 0,
			    min: 10,
			    max: 2048,
                values: [20, 120],
                slide: function (event, ui) {
                    if (ui.values[0] != ui.values[1]) {
                        $("#disk_total").val(ui.values[0] + " - " + ui.values[1] + "GB");
                    }
                    else {
                        $("#disk_total").val(ui.values[0] + "GB");
                    }
                },
                change: function (event, ui) {
                    var span = "<span class='label label-success' id='spanDiskTotal'>disk_total区间：" + ui.values[0] + "-" + ui.values[1] +
                     "GB <img alt='' src='/static/img/close.png' onclick='removeself(this)' /><input name='disk_total' type='hidden' value='"
                     + ui.values[0] + "-" + ui.values[1] + "' /></span> &nbsp;";
                    if ($("#spanDiskTotal").length == 0) {
                        $('#divSelectedType').append(span);
                    }
                    else {
                        $("#spanDiskTotal").html("disk_total区间：" + ui.values[0] + "-" + ui.values[1] +
                         "GB  <img alt='' src='/static/img/close.png' onclick='removeself(this)' /><input name='disk_total' type='hidden' value='"
                     + ui.values[0] + "-" + ui.values[1] + "' /></span> &nbsp;");
                    }
                    changepage(1);
                }
            });
            $("#disk_total").val($("#disk_total-range").slider("values", 0) +
			" - " + $("#disk_total-range").slider("values", 1) + "GB");              

			//使用组
            $('#selGroup').change(function () {
                if ($('#selGroup').val() != "") {
                    $("#hdnGroup").val($('#selGroup').val());
                    var span = "<span class='label label-success' id='spanGroup'>" + $("#selGroup").find("option:selected").text()
                    + " <img alt='' src='/static/img/close.png' onclick='removeself(this)' /><input name='group' type='hidden' value='"
                    + $('#selGroup').val() + "' /></span> &nbsp;";
                    if ($("#spanGroup").length == 0) {
                        $('#divSelectedType').append(span);
                    }
                    else {
                        $("#spanGroup").html($("#selGroup").find("option:selected").text()
                         + " <img alt='' src='/static/img/close.png' onclick='removeself(this)' /><input name='group' type='hidden' value='"
                         + $('#selGroup').val() + "' /></span> &nbsp;");
                    }
                    changepage(1);
                }
            })            

            //业务类型
            $('#selBusiness').change(function () {
                if ($('#selBusiness').val() != "") {
                    $("#hdnBusiness").val($('#selBusiness').val());
                    var span = "<span class='label label-success' id='spanBusiness'>" + $("#selBusiness").find("option:selected").text()
                    + " <img alt='' src='/static/img/close.png' onclick='removeself(this)' /><input name='business' type='hidden' value='"
                    + $('#selBusiness').val() + "' /></span> &nbsp;";
                    if ($("#spanBusiness").length == 0) {
                        $('#divSelectedType').append(span);
                    }
                    else {
                        $("#spanBusiness").html($("#selBusiness").find("option:selected").text()
                         + " <img alt='' src='/static/img/close.png' onclick='removeself(this)' /><input name='business' type='hidden' value='"
                         + $('#selBusiness').val() + "' /></span> &nbsp;");
                    }
                    changepage(1);
                }
            })
  
			//机房类型
            $('#selZone').change(function () {
                if ($('#selZone').val() != "") {
                    $("#hdnZone").val($('#selZone').val());
                    var span = "<span class='label label-success' id='spanZone'>" + $("#selZone").find("option:selected").text()
                    + " <img alt='' src='/static/img/close.png' onclick='removeself(this)' /><input name='put_zone' type='hidden' value='"
                    + $('#selZone').val() + "' /></span> &nbsp;";
                    if ($("#spanZone").length == 0) {
                        $('#divSelectedType').append(span);
                    }
                    else {
                        $("#spanZone").html($("#selZone").find("option:selected").text()
                         + " <img alt='' src='/static/img/close.png' onclick='removeself(this)' /><input name='put_zone' type='hidden' value='"
                         + $('#selZone').val() + "' /></span> &nbsp;");
                    }
                    changepage(1);
                }
            }) 

			//线路类型
            $('#selLine').change(function () {
                if ($('#selLine').val() != "") {
                    $("#hdnLine").val($('#selLine').val());
                    var span = "<span class='label label-success' id='spanLine'>" + $("#selLine").find("option:selected").text()
                    + " <img alt='' src='/static/img/close.png' onclick='removeself(this)' /><input name='line' type='hidden' value='"
                    + $('#selLine').val() + "' /></span> &nbsp;";
                    if ($("#spanLine").length == 0) {
                        $('#divSelectedType').append(span);
                    }
                    else {
                        $("#spanLine").html($("#selLine").find("option:selected").text()
                         + " <img alt='' src='/static/img/close.png' onclick='removeself(this)' /><input name='line' type='hidden' value='"
                         + $('#selLine').val() + "' /></span> &nbsp;");
                    }
                    changepage(1);
                }
            })    
            
			//设备状态
            $('#selStatus').change(function () {
                if ($('#selStatus').val() != "") {
                    $("#hdnStatus").val($('#selStatus').val());
                    var span = "<span class='label label-success' id='spanStatus'>" + $("#selStatus").find("option:selected").text()
                    + " <img alt='' src='/static/img/close.png' onclick='removeself(this)' /><input name='status' type='hidden' value='"
                    + $('#selStatus').val() + "' /></span> &nbsp;";
                    if ($("#spanStatus").length == 0) {
                        $('#divSelectedType').append(span);
                    }
                    else {
                        $("#spanStatus").html($("#selStatus").find("option:selected").text()
                         + " <img alt='' src='/static/img/close.png' onclick='removeself(this)' /><input name='status' type='hidden' value='"
                         + $('#selStatus').val() + "' /></span> &nbsp;");
                    }
                    changepage(1);
                }
            })  
            //购买年份
            $("#buy_time-range").slider({
			    range: "min",
			    value: 0,
			    min: 2000,
			    max: 2030,
                values: [2017,2019],
                slide: function (event, ui) {
                    if (ui.values[0] != ui.values[1]) {
                        $("#buy_time").val(ui.values[0] + " - " + ui.values[1] + "年");
                    }
                    else {
                        $("#buy_time").val(ui.values[0] + "年");
                    }
                },
                change: function (event, ui) {
                    var span = "<span class='label label-success' id='spanBuyTime'>购买年份：" + ui.values[0] + "-" + ui.values[1] +
                     "年 <img alt='' src='/static/img/close.png' onclick='removeself(this)' /><input name='buy_time' type='hidden' value='"
                     + ui.values[0] + "-" + ui.values[1] + "' /></span> &nbsp;";
                    if ($("#spanBuyTime").length == 0) {
                        $('#divSelectedType').append(span);
                    }
                    else {
                        $("#spanBuyTime").html("购买年份：" + ui.values[0] + "-" + ui.values[1] +
                         "年  <img alt='' src='/static/img/close.png' onclick='removeself(this)' /><input name='buy_time' type='hidden' value='"
                     + ui.values[0] + "-" + ui.values[1] + "' /></span> &nbsp;");
                    }
                    changepage(1);
                }
            });
            $("#buy_time").val($("#buy_time-range").slider("values", 0) +
			" - " + $("#buy_time-range").slider("values", 1) + "年");  
            //过保年份
            $("#expire_date-range").slider({
			    range: "min",
			    value: 2017,
			    min: 2000,
			    max: 2030,
                values: [2017,2019],
                slide: function (event, ui) {
                    if (ui.values[0] != ui.values[1]) {
                        $("#expire_date").val(ui.values[0] + " - " + ui.values[1] + "年");
                    }
                    else {
                        $("#expire_date").val(ui.values[0] + "年");
                    }
                },
                change: function (event, ui) {
                    var span = "<span class='label label-success' id='spanExpireDate'>过保年份：" + ui.values[0] + "-" + ui.values[1] +
                     "年 <img alt='' src='/static/img/close.png' onclick='removeself(this)' /><input name='expire_date' type='hidden' value='"
                     + ui.values[0] + "-" + ui.values[1] + "' /></span> &nbsp;";
                    if ($("#spanExpireDate").length == 0) {
                        $('#divSelectedType').append(span);
                    }
                    else {
                        $("#spanExpireDate").html("过保年份：" + ui.values[0] + "-" + ui.values[1] +
                         "年  <img alt='' src='/static/img/close.png' onclick='removeself(this)' /><input name='expire_date' type='hidden' value='"
                     + ui.values[0] + "-" + ui.values[1] + "' /></span> &nbsp;");
                    }
                    changepage(1);
                }
            });
            $("#expire_date").val($("#expire_date-range").slider("values", 0) +
			" - " + $("#expire_date-range").slider("values", 1) + "年");    
			//购买用户
            $('#selBuyUser').change(function () {
                if ($('#selBuyUser').val() != "") {
                    $("#hdnBuyUser").val($('#selBuyUser').val());
                    var span = "<span class='label label-success' id='spanBuyUser'>" + $("#selBuyUser").find("option:selected").text()
                    + " <img alt='' src='/static/img/close.png' onclick='removeself(this)' /><input name='buy_user' type='hidden' value='"
                    + $('#selBuyUser').val() + "' /></span> &nbsp;";
                    if ($("#spanBuyUser").length == 0) {
                        $('#divSelectedType').append(span);
                    }
                    else {
                        $("#spanBuyUser").html($("#selBuyUser").find("option:selected").text()
                         + " <img alt='' src='/static/img/close.png' onclick='removeself(this)' /><input name='buy_user' type='hidden' value='"
                         + $('#selBuyUser').val() + "' /></span> &nbsp;");
                    }
                    changepage(1);
                }
            })   
			//所属产品线
            $('#selProject').change(function () {
                if ($('#selProject').val() != "") {
                    $("#hdnProject").val($('#selProject').val());
                    var span = "<span class='label label-success' id='spanSelinux'>" + $("#selProject").find("option:selected").text()
                    + " <img alt='' src='/static/img/close.png' onclick='removeself(this)' /><input name='project' type='hidden' value='"
                    + $('#selProject').val() + "' /></span> &nbsp;";
                    if ($("#spanSelinux").length == 0) {
                        $('#divSelectedType').append(span);
                    }
                    else {
                        $("#spanSelinux").html($("#selProject").find("option:selected").text()
                         + " <img alt='' src='/static/img/close.png' onclick='removeself(this)' /><input name='project' type='hidden' value='"
                         + $('#selProject').val() + "' /></span> &nbsp;");
                    }
                    changepage(1);
                }
            }) 
            //系统类型
            $('#selSystem').change(function () {
                if ($('#selSystem').val() != "") {
                    $("#hdnProject").val($('#selSystem').val());
                    var span = "<span class='label label-success' id='spanSelinux'>" + $("#selSystem").find("option:selected").text()
                    + " <img alt='' src='/static/img/close.png' onclick='removeself(this)' /><input name='system' type='hidden' value='"
                    + $('#selSystem').val() + "' /></span> &nbsp;";
                    if ($("#spanSelinux").length == 0) {
                        $('#divSelectedType').append(span);
                    }
                    else {
                        $("#spanSelinux").html($("#selSystem").find("option:selected").text()
                         + " <img alt='' src='/static/img/close.png' onclick='removeself(this)' /><input name='system' type='hidden' value='"
                         + $('#selSystem').val() + "' /></span> &nbsp;");
                    }
                    changepage(1);
                }
            }) 
			//内核版本
            $('#selKernel').change(function () {
                if ($('#selKernel').val() != "") {
                    $("#hdnKernel").val($('#selKernel').val());
                    var span = "<span class='label label-success' id='spanKernel'>" + $("#selKernel").find("option:selected").text()
                    + " <img alt='' src='/static/img/close.png' onclick='removeself(this)' /><input name='kernel' type='hidden' value='"
                    + $('#selKernel').val() + "' /></span> &nbsp;";
                    if ($("#spanKernel").length == 0) {
                        $('#divSelectedType').append(span);
                    }
                    else {
                        $("#spanKernel").html($("#selKernel").find("option:selected").text()
                         + " <img alt='' src='/static/img/close.png' onclick='removeself(this)' /><input name='kernel' type='hidden' value='"
                         + $('#selKernel').val() + "' /></span> &nbsp;");
                    }
                    changepage(1);
                }
            })            
            
        })

        function search_go() {
            var parameter = {};
            $("input[type='hidden']").each(function () {
                var key = $(this).prop('name');
                var value = $(this).val();
                parameter[key] = value;
            })

            var count = 0;
            for (var i in parameter) {
                count += i;
                break;
            }
            if (count == 0) {
                return false;
            }

            $.post('/assets_search/', parameter, function (result) {
                if (result["data"].length > 0) {
                	 document.getElementById("div-search-result").style.display = "";	
					 var table = $('#dataTables-Search').dataTable();	                	
						 oSettings = table.fnSettings();
						 table.fnClearTable(this);
						 for (var i=0; i<result["data"].length; i++)
						 {
						   table.oApi._fnAddData(oSettings, result["data"][i]);
						 }
						 oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
						 table.fnDraw();                	               	
                }
                else{
                	//没有数据就清空
                	var table = $('#dataTables-Search').dataTable();
                	table.fnClearTable(this);
                }
            })
        }

        function changepage(pageindex) {
            curpage = pageindex;
            search_go();
        }

        function removeself(obj) {
            $(obj).parent().remove();
            changepage(1);
        }
        
    	function format ( dataList ) {
    	    var trHtml = '';
    		for (var i=0; i <dataList.length; i++){	
    			trHtml += '<tr><td>'+ dataList[i]["name"] +':</td>'+ '<td>'+ dataList[i]["value"] +'</td></tr>'			        
    		};	
     	    var vHtml = '<fieldset>' +
    		    			'<legend>硬件信息</legend>' +
    		    				'<table cellpadding="5" cellspacing="0" border="0" style="padding-left:50px;">'+ 
    		    				  trHtml  +
    		    				'</table>'
    					'</fieldset>'; 				
    	    return vHtml;
    	}	
     	
    	$(document).ready(function() {
    	    var table = $('#dataTables-Search').DataTable( {
    /* 	        "ajax": "../ajax/data/objects.txt", */
    	        "columns": [
    	            {
    	                "className": 'details-control',
    	                "orderable": false,
    	                "data":      null,
    	                "defaultContent": ''
    	            },
    	            { "data": "资产ID" },
    	            { "data": "资产类型" },
    	            { "data": "管理IP" },
    	            { "data": "资产编号" },
    	            { "data": "设备型号" },
    	            { "data": "放置区域" },
    	            { "data": "产品线" },
    	            { "data": "业务类型" },
    	            { "data": "使用组" },
    	            { "data": "设备状态" },
    	            { "data": "操作" }
    	        ],
    	        "order": [[2, 'asc']]
    	    } );
    	     
    	    // Add event listener for opening and closing details
    	    $('#dataTables-Search tbody').on('click', 'td.details-control', function () {
    	    	var dataList = [];
    	        var tr = $(this).closest('tr');
    	        var row = table.row( tr );
    	        aId = row.data()["资产ID"];
    	        console.log(aId);
    	        $.ajax({
    	            url : "/api/assets/info/"+aId+"/",
    	            type : "post",
    	            async : false,
    	            data : {"id":aId},
    	            dataType : "json",
    	            success : function(result) {
    	            	dataList = result.data;
    	            }
    	        });	        
    /* 	    	console.log(dataList); */
    	        if ( row.child.isShown() ) {
    	            // This row is already open - close it
    	            row.child.hide();
    	            tr.removeClass('shown');
    	        }
    	        else {
    	            // Open this row
    	            row.child( format(dataList) ).show();
    	            tr.addClass('shown');
    	        }
    	    } );
    	} ); 
        
</script>

<script type="text/javascript">

		function assetsUpdate(obj, id,ip,type){
			var btnObj = $(obj);
			var txt=  "是否确认更新？";
			var option = {
					title: "更新主机("+ip+")硬件信息",
					btn: parseInt("0011",2),
					onOk: function(){
						$.ajax({
							  type: 'POST',
							  url: '/assets_facts/',
							  data:{
									"ip":ip,
									"server_id":id,
									"type":type
								},
						      success:function(response){			            
					                if (response["code"]=="200"){ 
					                	window.wxc.xcConfirm(response["msg"], window.wxc.xcConfirm.typeEnum.success);
		
					                }
						        	else{
						        		window.wxc.xcConfirm(response["msg"], window.wxc.xcConfirm.typeEnum.error);
						        	}						                
							},
				            error:function(response){
				            	window.wxc.xcConfirm("请求数据错误！", window.wxc.xcConfirm.typeEnum.error);
				            },		
							});
					},
					onCancel:function(){	
					},
					onClose:function(){
					}
				}			
			window.wxc.xcConfirm(txt, "custom", option);
		}
		
		function deleteAssets(obj,id){
			var txt=  "是否确认删除？";
			var btnObj = $(obj);
			btnObj.attr('disabled',true);
			var option = {
				title: "删除当前资产",
				btn: parseInt("0011",2),
				onOk: function(){
					$.ajax({
						  type: 'DELETE',
						  url: '/api/assets/'+id+'/',
					      success:function(response){	
					    	btnObj.removeAttr('disabled');
				            window.wxc.xcConfirm("删除成功", window.wxc.xcConfirm.typeEnum.success);
				            location.reload('/assets_list/');
					      },
			              error:function(response){
			            	btnObj.removeAttr('disabled');
			            	window.wxc.xcConfirm("删除失败！", window.wxc.xcConfirm.typeEnum.error);	
			              }
						});
				},
				onCancel:function(){	
				},
				onClose:function(){
				}
			}
			window.wxc.xcConfirm(txt, "custom", option);			   
		}
	
	
	
	  {% if errorInfo %}
	  	window.wxc.xcConfirm("{{errorInfo}}", window.wxc.xcConfirm.typeEnum.error);
	  {% endif %}
</script>

{% endblock %}